package com.hdoit.ares.logical.app.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.app.dao.IAppRemindMessageDao;
import com.hdoit.ares.logical.app.model.AppRemindMessage;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      xieqixiu
 * @email       
 * @createtime  2018年03月28日 15:13:52
 * @comment
 */
@Component
public class AppRemindMessageDaoImpl extends SuperDao<AppRemindMessage> implements IAppRemindMessageDao{

	@Override
	public List<AppRemindMessage> queryMessageList(String custId,Integer pageNum, Integer length) {
		
		
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
		                .from(AppRemindMessage.class)
		                .andWhere("custId=#{custId}")
		                .setParam("custId", custId)
		                .addOrder("createTime", OrderEnum.desc);
		if(pageNum != null && length !=null){
			 int start=(pageNum-1)*length;
			finderExpression.limit(start, length);
		}
		
		return queryList(finderExpression);
	}

	@Override
	public int selectUnReadCount(String custId) {
		
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("count(*)")
		                .from(AppRemindMessage.class)
		                .andWhere("custId=#{custId}")
		                .andWhere("messageStatus=#{messageStatus}")
		                .setParam("messageStatus", "unRead")
		                .setParam("custId", custId);
		return queryCount(finderExpression);
	}

}